package ttt;

import static org.junit.Assert.*;

import org.junit.Test;

public class JunitTest {
	

	@Test
	/** In this test, the board is filled in a manner that the human wins by 
	 	a diagnonal victory. The positionValueTester should return value of '0',
	 	meaning that the Human has won.	
	**/
	
	public void positionValueTester() throws Exception {
		try {
			TicTacToe tester = new TicTacToe();
			int side = 0;
			
			for(int i=0; i < tester.board[0].length ; i++){
				
				
				for(int j=0; j < tester.board.length; j++){
				tester.place(i, j, side);
				
				if (side==0) side++;
				else side--;		
				}}
		assertEquals(0, tester.positionValue());
			
		}catch(Exception e){
			fail("Not yet implemented");
		}
	}

	@Test
	/** In this test, the board is filled in a manner that the computer wins
	  by horizontal victory. The isAWinTester should return 'true',
	 	meaning that the computer has won.	
	**/
	
	public void isAWinTester() throws Exception {
		try {
		TicTacToe tester = new TicTacToe();
		int side = 1;
		
		for(int i=0; i <3;i++){
		tester.place(0,i,side);
		}
		
		assertEquals(true, tester.isAWin(side));
		
		
		}catch(Exception e){
			fail("Not yet implemented");
		}
	}
	
	@Test
	/** In this test, the board is filled in a manner that there are 2 winning moves left for
	 * the computer. The chooseMoveTester should return the first winning move '6'.
	**/
	
	public void chooseMoveTester() throws Exception{
		try{
			
			TicTacToe tester = new TicTacToe();
			int side = 1;
			
			for(int i = 0; i < 6;i++)
			{
				tester.place(i/3,i%3,side);		
				System.out.println(tester.toString());
				if (side==0) side++;
				else side--;	
			}
			assertEquals(6,tester.chooseMove());
			
			
		} catch(Exception e){
			fail("Not yet implemented");
		}
		
		
		
	}
	
}
